package cn.wgoodq.study.MultiThreading.exercise.entity;

/**
 * Created by OuKyou on 2017/1/21.
 */
public class ParkinglotUser implements Runnable {
    private String name;
    private Parkinglot parkinglot;
    private boolean flag = true;

    public ParkinglotUser(String name, Parkinglot parkinglot, boolean flag) {
        this.name = name;
        this.parkinglot = parkinglot;
        this.flag = flag;
    }

    @Override
    public void run() {
        try {
            int cnt = 10;
            if (!flag) {
                cnt = 60;
            }
            for (int i = 0; i < cnt; i++) {
                if (flag) {
                    parkinglot.cunChe(name);
                } else {
                    Thread.sleep(500);
                    parkinglot.quChe(name);
                }
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
